<?php
namespace Common\Model;
use Common\Model\BaseModel;
/**
* 学校标签关联表model
*/
class ArticleProjectModel extends BaseModel{

    /**
     * 添加数据
     * @param string $aid 学校id
     * @param array $tids 标签id
     */
    public function addData($aid,$pid,$b_time,$f_time){

            $data=array(
                'aid'=>$aid,
                'pid'=>$pid,
                'b_time'=>$b_time,
                'f_time'=>$f_time
                );
            $this->add($data);

        return true;
    }



    // 传递aid和true时获取tid数组；传递aid和tname获得键名为aid键值为tname的数组
    public function getDataByAid($aid){
        $data=$this->where(array('aid'=>$aid))->select();
        foreach($data as $k=>$v){
            $p=D('Project')->where(array('pid'=>$v['pid']))->find();
            $o_name=D('Org')->where(array('oid'=>$p['oid']))->getField('o_name');
            $data[$k]['description']=$p['description'];
            $data[$k]['comments']=D('Comment')->getChildData($v['pid'],2,$aid);
            $data[$k]['comments_num']=count( $data[$k]['comments']);
            $data[$k]['p_name']=$p['p_name'];
            $data[$k]['o_name']=$o_name;
            $fathername=D('Project')->where(array('pid'=>$data['father']))->getField('p_name');
            $data[$k]['father-alt']=$fathername;
            $data[$k]['time']=date('Y-m-d',$v['b_time']).'～'.date('Y-m-d',$v['f_time']);
        }
        return $data;
    }


}




